package demo;

import dao.CourseDao;
import dao.ScoreDao;
import dao.StudentDao;
import model.Course;
import model.Score;
import model.Student;

import java.text.MessageFormat;
import java.util.List;
import java.util.Scanner;

/**
 * @author tongchen
 * @create 2022-12-29 13:58
 */
public class exer7 {
    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        CourseDao courseDao = new CourseDao();
        List<Course> courses = courseDao.selectAll();
        if(courses==null||courses.isEmpty()){
            System.out.println("本次查询为空，轻稍后再试");
        }
        for (Course course:courses) {
            String format = MessageFormat.format("id:{0}\t|name:{1}\t",course.getId(),course.getName());
            System.out.println(format);
        }
        System.out.println("请输入学生姓名");
        String name=scanner.next();
        StudentDao studentDao = new StudentDao();
        List<Student> students = studentDao.selectOne(name);
        if(students==null||students.isEmpty()){
            System.out.println("没有该学生");
            return;
        }
        for (Student student:students) {
            String format = MessageFormat.format("学生ID:{0}\t|sn:{1}\t|name:{2}\t|email:{3}\t|classid:{4}\t|",
                    student.getId(), student.getSn(), student.getName(), student.getEmail(), student.getClassId());
            System.out.println(format);
        }
        System.out.println("请输入学生编号：");
        int studentId = scanner.nextInt();

        System.out.println("请输入课程编号：");
        int courseId = scanner.nextInt();
        Score score = new Score();
        score.setCoourseId(courseId);
        score.setStudentId(studentId);
        ScoreDao scoreDao = new ScoreDao();
        int delete = scoreDao.delete(score);
        if(delete>0){
            System.out.println("删除成功");
        }else{
            System.out.println("删除失败");
        }
    }
}
